﻿#include "widget.h"
#include <QApplication>
#include <QDebug>

#include <QPluginLoader>
#include <QDir>
#include <QMessageBox>
#include "../AutoUpdate/autoupdateinterface.h"
bool loadPlugin(){
    //"../build-AutoUpdate-Desktop_Qt_5_4_2_MinGW_32bit-Release/release"
    QString pluginName = QDir::currentPath()+"/autoupdateplugin.dll";//pluginsDir.absoluteFilePath("autoupdateplugin.dll")//发布用
//    QString pluginName = QString("../build-AutoUpdate-Desktop_Qt_5_4_2_MinGW_32bit-Release/release") + "/autoupdateplugin.dll";//测试用
    qDebug() << pluginName;
    QPluginLoader pluginLoader(pluginName);
    QObject *plugin = pluginLoader.instance();
    if(plugin){
        TKG::AutoUpdateInterface *m_interface = qobject_cast<TKG::AutoUpdateInterface*>(plugin);
        if(m_interface){
            m_interface->initUpdateExecName("./tkgup.exe","测试更新程序");
            m_interface->initRemoteConfig("http://139.129.44.147");
            if(m_interface->checkUpdate("abc","nouser","nopass")){
                exit(0);
            }else{
                return false;
            }
        }else{
            return false;
        }
    }
    QMessageBox::information(0,"info",pluginLoader.errorString());
    return false;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    loadPlugin();
    return a.exec();
}
